
#ifndef ROMS_MENU_H_
#define ROMS_MENU_H_

#include "std_lib_facilities.h"
#include <map> //HHC Part II D.1
//other types
#include "Category.h"
#include "Menu_Item.h"
#include "Recipe.h"
#include "Ingredient.h"
#include "Order.h"
#include "Order_Item.h"

using namespace std;

namespace ROMS{   
	
	enum Msg_type{
	Exit_program=1, About_info, About_help, Close_about_box,
	Read_recipes_ingredients, Read_orders, Read_category_menu_items,
	Show_order, Show_recipe, Show_menu,
	Find_category_sales, Find_table_sales, Find_menu_item_sales,
	Update_add_order_item, Update_add_menu_item, Update_add_recipe,
	Tables_button, Orders_button, Categories_button, Recipes_button, Menu_items_button,
	Display_window, Menu_bar_cb,
	do_Find_menu_item_sales, do_Update_menu_item, //HHC Part II C
	Close_find_category_sales, Find_category_sales_button, Close_add_recipe, Add_recipe_button, //[THORIQ-C]
	do_update_order_items, Find_table_sales_button, Close_find_table_sales,//TTL Part C
	Graph_button, Graph_month_button, Graph_table_button, Graph_cat_month_button//TTL PartD
	};
   
	struct InvalidType : std::runtime_error {
	  InvalidType(): runtime_error("Invalid type data") {}
	};

class ROMS_Menu {
public:
   struct InvalidData : std::runtime_error {
      InvalidData(): runtime_error("Invalid input data format") {}
   };

   struct InvalidFile : std::runtime_error {
      InvalidFile(): runtime_error("Invalid input file name") {}
   };

   enum Main_menu_options{ Info=1, Read, Show, Find, Update, Exit }; 

   enum Rec_type{ Cats=1, Menu_entry, Rec, Ingred, Ord, Ord_item };

   enum File_type{	Tbls=Tables_button, 
					CatMI=Categories_button, 
					Prds=Menu_items_button, 
					Carts=Orders_button, 
					Items=Recipes_button }; 

   string recipe_location, catmenu_location, order_location; //added by HHC
		
	ROMS_Menu();
   
   void display_main_menu() const;
   void display_info() const;//display assignment info & your name plus "Project Part I"
   void read();		 
   void update();
   void show() const;
   void find() const;
   void read_recipes_ingredients(string);
   void Read_orders(string);
   void read_catprds(string);
   void save(); //TTL B.1

   //ADDED FUNCTIONS
   //string show_menu_item(); //HHC Part II B.3
   //Category getCatByCatID (int CatID) const; //HHC Part II B.3
   string show_category(); //HHC Part II B.3
   string show_order_item(); //HHC Part II B.3
   string getMenuItemsByCatID (int CatID) const; //HHC Part II B.3
   Order getOrderByOrderID (int OrderID) const; //HHC Part II B.3

   string findSalesByMenuItemID (int MIID); //HHC Part II C
   Menu_Item getMenuItemByID(int MenuitemID); //HHC Part II C
   bool updateMenuItem(int MenuitemID, int catID, int recID, string name, double prc, string desc); //HHC Part II C
   vector<Menu_Item> get_menu_items() {return menu_items;};//HHC Part II C
   vector<Order> get_orders(){return orders;};//TTL Part C
   vector<Order_Item> get_order_items(){return order_items;};//TTL Part C
   void updateOrderItem(string seatid, int orderid, int menuitemid, int qnty); //TTL PartC
   int getMonthbyOrderID(int OrderID); //HHC Part II D.1
   map<int,double> getPricelist(); //HHC Part II D.1
   map<int,double> get_sales_per_month(); //HHC Part II D.1
   //***************
   	
   //show functions added to support GUI interface
   string show_button(Msg_type);

	/**********************[THORIQ-B.2]**************************/
	//Show functions for menu bar
	string show_menu(Msg_type);
	//split outputs for the main window
	string split_output(string s);
	/*********************[THORIQ-C]****************************/
	//return total sales from the specified category
	double get_category_sales(int);
	//return true if category with the specified ID is found within categories vector
	bool is_category_available(int);
	//add new recipe to recipes vector
	string add_recipe(int, string, string);
	/*********************[THORIQ-D]****************************/
	//return the total sales of the specified category per month
	vector<double> get_category_sales_per_month(int cat_id);
	//return a map containing the percentage of each category sales per month
	map<int,map<int,double> > get_category_percentage();
	//return the categories vector
	vector<Category> get_category_list() { return categories; };
	/***********************************************************/
	
	
	template <typename T>
	string show_func(T t, string s)
	{
		string r;
		if(0==t.size())
			r = "No "+s+" Data Loaded\n";
		else
			for(int i=0; i<t.size(); ++i)
			{
				r+=t[i].display();
				r+="\n";
			}
		return r;
	}

	template <typename T>
	string show_func_w_header(T t, string s)
	{
		string r;
		if(0==t.size())
			r = "No "+ s +" Data Loaded\n";
		else {
			r += t[0].header() + "\n";
			for(int i=0; i<t.size(); ++i)
			{
				r+=t[i].display();
				r+="\n";
			}
		}
		return r;
	}
private:
   //private data
	vector<Category> categories;
	vector<Menu_Item> menu_items;
	vector<Recipe> recipes;
	vector<Ingredient> ingredients;
	vector<Order> orders;
	vector<Order_Item> order_items;


	int get_file_info(ifstream& ist, string prompt, string fname);	//A.1,2,3 merge added a function for common code
	void read_file(ifstream& file, int num_rec, Rec_type ftype);
	string get_long_string(ifstream& ist);
};
} //end namespace ROMS

#endif //ROMS_MENU_H_
